import 'dart:io';
import 'package:valovault_reminder/common/config/val_assets_name.dart';
import 'package:flutter/material.dart';

class ValUserPublishCardContentCell extends StatefulWidget {
  final String contentText;
  final String userName;
  final String imageName;
  final String userHeader;
  final bool showDelete;
  final VoidCallback? onTapCard; //点cell
  final VoidCallback? onTapDelete; //点删除

  const ValUserPublishCardContentCell({super.key, this.contentText = '', this.userName = '',
    this.imageName = '', this.userHeader = '', this.onTapCard, this.onTapDelete, this.showDelete = true});

  @override
  State<ValUserPublishCardContentCell> createState() => _ValUserPublishCardContentCellState();
}

class _ValUserPublishCardContentCellState extends State<ValUserPublishCardContentCell> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: widget.onTapCard,
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(22.0),
          gradient: const LinearGradient(
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
            colors: [
              Color(0xFFE8A229),
              Color(0xFFF9C03D),
              Color(0xFFFCCC41),
            ],
          ),
        ),
        child: Column(
          children: [
            Expanded(
              flex: 128,
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: const BorderRadius.only(topLeft: Radius.circular(8.0), topRight: Radius.circular(8.0)),
                  image: widget.imageName.contains('flutter-images') ? DecorationImage(
                      image: FileImage(File(Directory.systemTemp.path + widget.imageName)), fit: BoxFit.fill) :
                    DecorationImage(image:AssetImage(ValAssetsName.ASSETS_Message + widget.imageName), fit: BoxFit.fill),
                ),
                child: Stack(
                  children: [
                    if (widget.showDelete)
                    Positioned(
                      top: 7, right: 7,
                      child: GestureDetector(
                        onTap: widget.onTapDelete,
                        child: Image.asset('${ValAssetsName.ASSETS_HOME}val_home_car_delete_btn.png', width: 25, height: 25)
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Expanded(
              flex: 58,
              child: Container(
                color: Colors.transparent,
                padding: const EdgeInsets.only(left: 10,bottom: 8, right: 10),
                alignment: Alignment.center,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    const Padding(padding: EdgeInsets.only(top: 8)),
                    Expanded(
                      child: Text(widget.contentText, maxLines: 1,
                        textAlign: TextAlign.center,
                        style: const TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.w500),),
                    ),
                    SizedBox(
                      height: 20,
                      child: Text(widget.userName,
                        textAlign: TextAlign.center, maxLines: 1,
                        style: const TextStyle(color: Color(0xFF666666), fontSize: 10),),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
